*-------------------------------------------------------------------------------------------------------------*
* The Causal Effects of R&D Grants: Evidence from a Regression Discontinuity (Santoleri et al., 2020)
*-------------------------------------------------------------------------------------------------------------*

/// Table 4 (Panel A): The effects on cite-weighted patents

use $data_path/DATA_ALL_FINAL.dta, clear 

* dependent var, treatment var, pre-treatment var
local dvar ln_citw_patents_post_w award ln_citw_patents_pre_w

* controls for polinomyal orders on both sides of the threshold
global linear    c.rank#i.award
global quadratic c.rank#i.award c.rank#c.rank#i.award

* regression loops reproducing Table 4
est clear
forv i=2/2 {
             eststo: reghdfe `dvar' $linear    if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' i.quintile if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $linear    if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $linear    if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
}
* display results of Table 4 in .txt format
cap erase $output/Table_4.txt $output/Table_4.tex
esttab est* using $output/Table_4.txt, replace star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat(N r2 bic, fmt(0 2 2)) title(The effects on cite-weighted patents) mtitles(All All All 10 10 5 5 ) ///
coeflabels(award "Grant") indicate( "Rank x Grant=*award#c.rank" "Rank2 x Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile" ) varwidth(25) nonotes

* display results of Table 4 in .tex format
esttab est* using $output/Table_4.tex, replace star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) stats(N   r2 bic, fmt(0 2 2) labels(N "R-squared" "BIC")) keep(award) ///
coeflabels(award "Grant") mtitles(All All All 10 10 5 5 ) prehead(\begin{table}[htbp]\centering \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \caption{The effects on cite-weighted patents} \begin{tabular}{l*{9}{c}} \toprule) ///
postfoot(\bottomrule \end{tabular}  \end{table}) posthead(\midrule) booktabs nonotes indicate( "Rank $\times$ Grant=*.award#c.rank" "Rank^{2} $\times$ Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile"  ) varwidth(25)


/// Table 4 (Panel B): The effects on private equity

* dependent var, treatment var, pre-treatment var
local dvar pe_post award pe_pre

* controls for polinomyal orders on both sides of the threshold
global linear    c.rank#i.award
global quadratic c.rank#i.award c.rank#c.rank#i.award

* regression loops reproducing Table 4
est clear
    forv i=2/2 {
             eststo: reghdfe `dvar' $linear    if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' i.quintile if phase_smei==`i', a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $linear    if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $linear    if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
			 eststo: reghdfe `dvar' $quadratic if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
}
* display results of Table 4 in .txt format
esttab est* using $output/Table_4.txt, append star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat(N r2 bic, fmt(0 2 2)) title(The effects on private equity financing) mtitles(All All All 10 10 5 5 ) ///
coeflabels(award "Grant") indicate( "Rank x Grant=*award#c.rank" "Rank2 x Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile" ) varwidth(25) nonotes

* display results of Table 4 in .tex format
esttab est* using $output/Table_4.tex, append star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) stats(N   r2 bic, fmt(0 2 2) labels(N "R-squared" "BIC")) keep(award) ///
coeflabels(award "Grant") mtitles(All All All 10 10 5 5 ) prehead(\begin{table}[htbp]\centering \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \caption{The effects on private equity financing} \begin{tabular}{l*{9}{c}} \toprule) ///
postfoot(\bottomrule \end{tabular}  \end{table}) posthead(\midrule) booktabs nonotes indicate( "Rank $\times$ Grant=*.award#c.rank" "Rank^{2} $\times$ Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile"  ) varwidth(25)








